<template>
    <div>
        <Modal :title="modalTitle" v-model="modalShow" :width="modalWidth" :mask-closable="false" :closable="false">
            <div v-show="modalType === 'edit' || modalType === 'add'">
                <Form ref="formItem" :rules="ruleValidate" label-position="right" :model="formItem" :label-width="130">
                    <!--<FormItem label="类别：" prop="category_id">
                        <Select v-model="formItem.category_id" placeholder="请选择类别" filterable>
                            <Option v-for="(option, index) in categoryObj" :value="option.id" :key="index">{{option.category}}</Option>
                        </Select>
                    </FormItem>-->
                    <div v-show="modalType === 'edit'">
                        <FormItem label="单位编码：" prop="company_code">
                            <Input type="text" v-model="formItem.company_code" clearable></Input>
                        </FormItem>
                        <FormItem label="单位名称：" prop="company_name">
                            <Input type="text" v-model="formItem.company_name" clearable></Input>
                        </FormItem>
                    </div>
                    <Alert>确诊病例人数</Alert>
                    <FormItem label="和平区：" prop="jgmc">
                        <Input type="number" v-model="formItem.qzblldfxmjz_heping" clearable></Input>
                    </FormItem>
                    <FormItem label="沈河区：" prop="sycws">
                        <Input type="number" v-model="formItem.qzblldfxmjz_shenhe" clearable></Input>
                    </FormItem>
                    <FormItem label="铁西区：" prop="zyyss">
                        <Input type="number" v-model="formItem.qzblldfxmjz_tiexi" clearable></Input>
                    </FormItem>
                    <FormItem label="皇姑区：" prop="zchss">
                        <Input type="number" v-model="formItem.qzblldfxmjz_huanggu" clearable></Input>
                    </FormItem>
                    <FormItem label="大东区：" prop="jgmc">
                        <Input type="number" v-model="formItem.qzblldfxmjz_dadong" clearable></Input>
                    </FormItem>
                    <FormItem label="浑南区：" prop="sycws">
                        <Input type="number" v-model="formItem.qzblldfxmjz_hunnan" clearable></Input>
                    </FormItem>
                    <FormItem label="于洪区：" prop="zyyss">
                        <Input type="number" v-model="formItem.qzblldfxmjz_yuhong" clearable></Input>
                    </FormItem>
                    <FormItem label="沈北区：" prop="zchss">
                        <Input type="number" v-model="formItem.qzblldfxmjz_shenbei" clearable></Input>
                    </FormItem>
                    <FormItem label="苏家屯：" prop="jgmc">
                        <Input type="number" v-model="formItem.qzblldfxmjz_sujiatun" clearable></Input>
                    </FormItem>
                    <FormItem label="辽中：" prop="sycws">
                        <Input type="number" v-model="formItem.qzblldfxmjz_liaozhong" clearable></Input>
                    </FormItem>
                    <FormItem label="新民：" prop="zyyss">
                        <Input type="number" v-model="formItem.qzblldfxmjz_xinmin" clearable></Input>
                    </FormItem>
                    <FormItem label="法库：" prop="zchss">
                        <Input type="number" v-model="formItem.qzblldfxmjz_faku" clearable></Input>
                    </FormItem>
                    <FormItem label="康平：" prop="jgmc">
                        <Input type="number" v-model="formItem.qzblldfxmjz_kangping" clearable></Input>
                    </FormItem>
                    <Alert>疑似病例人数</Alert>
                    <FormItem label="和平区：" prop="sycws">
                        <Input type="number" v-model="formItem.ysblldfxmjz_heping" clearable></Input>
                    </FormItem>
                    <FormItem label="沈河区：" prop="zyyss">
                        <Input type="number" v-model="formItem.ysblldfxmjz_shenhe" clearable></Input>
                    </FormItem>
                    <FormItem label="铁西区：" prop="zchss">
                        <Input type="number" v-model="formItem.ysblldfxmjz_tiexi" clearable></Input>
                    </FormItem>
                    <FormItem label="皇姑区：" prop="jgmc">
                        <Input type="number" v-model="formItem.ysblldfxmjz_huanggu" clearable></Input>
                    </FormItem>
                    <FormItem label="大东区：" prop="sycws">
                        <Input type="number" v-model="formItem.ysblldfxmjz_dadong" clearable></Input>
                    </FormItem>
                    <FormItem label="浑南区：" prop="zyyss">
                        <Input type="number" v-model="formItem.ysblldfxmjz_hunnan" clearable></Input>
                    </FormItem>
                    <FormItem label="于洪区：" prop="zchss">
                        <Input type="number" v-model="formItem.ysblldfxmjz_yuhong" clearable></Input>
                    </FormItem>
                    <FormItem label="沈北区：" prop="jgmc">
                        <Input type="number" v-model="formItem.ysblldfxmjz_shenbei" clearable></Input>
                    </FormItem>
                    <FormItem label="苏家屯：" prop="sycws">
                        <Input type="number" v-model="formItem.ysblldfxmjz_sujiatun" clearable></Input>
                    </FormItem>
                    <FormItem label="辽中：" prop="zyyss">
                        <Input type="number" v-model="formItem.ysblldfxmjz_liaozhong" clearable></Input>
                    </FormItem>
                    <FormItem label="新民：" prop="zchss">
                        <Input type="number" v-model="formItem.ysblldfxmjz_xinmin" clearable></Input>
                    </FormItem>
                    <FormItem label="法库：" prop="zchss">
                        <Input type="number" v-model="formItem.ysblldfxmjz_faku" clearable></Input>
                    </FormItem>
                    <FormItem label="康平：" prop="zchss">
                        <Input type="number" v-model="formItem.ysblldfxmjz_kangping" clearable></Input>
                    </FormItem>
                </Form>
            </div>
            <div v-show="modalType === 'info'">
                <Form label-position="right" :model="formItem" :label-width="150">
                    <Alert>确诊病例人数</Alert>
                    <FormItem label="和平区：" prop="jgmc">
                        {{formItem.qzblldfxmjz_heping}}  人
                    </FormItem>
                    <FormItem label="沈河区：" prop="sycws">
                        {{formItem.qzblldfxmjz_shenhe}}  人
                    </FormItem>
                    <FormItem label="铁西区：" prop="zyyss">
                        {{formItem.qzblldfxmjz_shenhe}}  人
                    </FormItem>
                    <FormItem label="皇姑区：" prop="zchss">
                        {{formItem.qzblldfxmjz_huanggu}}  人
                    </FormItem>
                    <FormItem label="大东区：" prop="jgmc">
                        {{formItem.qzblldfxmjz_dadong}}  人
                    </FormItem>
                    <FormItem label="浑南区：" prop="sycws">
                        {{formItem.qzblldfxmjz_hunnan}}  人
                    </FormItem>
                    <FormItem label="于洪区：" prop="zyyss">
                        {{formItem.qzblldfxmjz_yuhong}}  人
                    </FormItem>
                    <FormItem label="沈北区：" prop="zchss">
                        {{formItem.qzblldfxmjz_shenbei}}  人
                    </FormItem>
                    <FormItem label="苏家屯：" prop="jgmc">
                        {{formItem.qzblldfxmjz_sujiatun}}  人
                    </FormItem>
                    <FormItem label="辽中：" prop="sycws">
                        {{formItem.qzblldfxmjz_liaozhong}}  人
                    </FormItem>
                    <FormItem label="新民：" prop="zyyss">
                        {{formItem.qzblldfxmjz_xinmin}}  人
                    </FormItem>
                    <FormItem label="法库：" prop="zchss">
                        {{formItem.qzblldfxmjz_faku}}  人
                    </FormItem>
                    <FormItem label="康平：" prop="jgmc">
                        {{formItem.qzblldfxmjz_kangping}}  人
                    </FormItem>
                    <Alert>疑似病例人数</Alert>
                    <FormItem label="和平区：" prop="sycws">
                        {{formItem.ysblldfxmjz_heping}}  人
                    </FormItem>
                    <FormItem label="沈河区：" prop="zyyss">
                        {{formItem.ysblldfxmjz_shenhe}}  人
                    </FormItem>
                    <FormItem label="铁西区：" prop="zchss">
                        {{formItem.ysblldfxmjz_tiexi}}  人
                    </FormItem>
                    <FormItem label="皇姑区：" prop="jgmc">
                        {{formItem.ysblldfxmjz_huanggu}}  人
                    </FormItem>
                    <FormItem label="大东区：" prop="sycws">
                        {{formItem.ysblldfxmjz_dadong}}  人
                    </FormItem>
                    <FormItem label="浑南区：" prop="zyyss">
                        {{formItem.ysblldfxmjz_hunnan}}  人
                    </FormItem>
                    <FormItem label="于洪区：" prop="zchss">
                        {{formItem.ysblldfxmjz_yuhong}}  人
                    </FormItem>
                    <FormItem label="沈北区：" prop="jgmc">
                        {{formItem.ysblldfxmjz_shenbei}}  人
                    </FormItem>
                    <FormItem label="苏家屯：" prop="sycws">
                        {{formItem.ysblldfxmjz_sujiatun}}  人
                    </FormItem>
                    <FormItem label="辽中：" prop="zyyss">
                        {{formItem.ysblldfxmjz_liaozhong}}  人
                    </FormItem>
                    <FormItem label="新民：" prop="zchss">
                        {{formItem.ysblldfxmjz_xinmin}}  人
                    </FormItem>
                    <FormItem label="法库：" prop="zchss">
                        {{formItem.ysblldfxmjz_faku}}  人
                    </FormItem>
                    <FormItem label="康平：" prop="zchss">
                        {{formItem.ysblldfxmjz_kangping}}  人
                    </FormItem>
                </Form>
            </div>
            <div slot="footer">
                <template v-if="modalType === 'edit' || modalType === 'add'">
                    <Button type="text" @click="cancelOption">取消</Button>
                    <Button type="success" @click="saveOption" :loading="btnLoading">保存</Button>
                </template>
                <template v-if="modalType === 'info'">
                    <Button type="text" @click="cancelOption">关闭</Button>
                </template>
            </div>
        </Modal>
    </div>
</template>

<script>
import { getLudiaeInfo, updateLudiae, insertLudiae } from '@/api/yuyq'
export default {
  name: 'optionModal',
  props: {
    modalTitle: {
      type: String,
      default: () => {
        return ''
      }
    },
    modalType: {
      type: String,
      default: () => {
        return 'info'
      }
    },
    modalShow: {
      type: Boolean,
      default: () => {
        return false
      }
    },
    modalWidth: {
      type: Number,
      default: () => {
        return 800
      }
    },
    dataObj: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      ruleValidate: {
        category_id: [
          { required: true, message: '类型不能为空', trigger: 'change' }
        ]
      },
      btnLoading: false,
      formItem: {},
      categoryObj: {}
    }
  },
  methods: {
    save (data) {
      insertLudiae(data).then(ret => {
        console.log(ret.data.errcode)
        if (ret.data.errcode === 0) {
          this.$emit('saveOption')
        }
      })
    },
    getLudiaeInfo () {
      let data = {
        id: this.formItem.id
      }
      getLudiaeInfo(data).then(ret => {
        console.log(ret.data)
      })
    },
    cancelOption () {
      this.$emit('saveOption')
    },
    saveOption () {
      let param = {}
      if (this.modalType === 'add') {
        param = this.formItem
        if (!param.qzblldfxmjz_heping) {
          this.$Message.error({
            content: '操作失败,请核对添加信息后重试'
          })
          return
        }
        console.log(param)
        this.save(param)
        // this.$delete(param, 'id')
      } else if (this.modalType === 'edit') {
        param = this.formItem
        updateLudiae(param).then(ret => {
          this.cancelOption()
          console.log(ret.data)
        })
      }
      /* this.$refs['formItem'].validate((valid) => {
        alert(valid)
        if (valid) {
          this.btnLoading = true
        } else {
          this.$Message.error({
            content: '操作失败,请核对添加信息后重试'
          })
        }
      }) */
    },
    success (val) {
      val = this.$common.xeUtils.isEmpty(val) ? '操作成功' : val
      this.$Message.success(val)
    },
    error (data) {
      this.$Message.error({
        content: '操作失败,\n' + data.errmsg
      })
    }
  },
  mounted () {

  },
  watch: {
    dataObj (val) {
      this.formItem = val
    },
    modalType (data) {
      if (data !== 'add') {
        this.getLudiaeInfo()
      }
    }

  },
  computed: {}
}
</script>

<style scoped>
    /deep/ .ivu-alert-info {
        border: 1px solid #EDEFF0;
        background-color: #F8F8F9;
    }
</style>
